<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>意见</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layuis/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../res/layuis/dist/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/login_common.js" charset="UTF-8"></script>
</head>
<body>
<form class="layui-form layui-header" action="" lay-filter="example">
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label">附件表id</label>
        <input class="layui-input-block">
        <input type="text" name="attachId" id="attachId" value="" class="layui-input" style="width: 280px">
    </div>
</form>
<table class="layui-hide" id="demo" lay-filter="test"></table>

<script type="text/html" id="tempLetState">
    {{#  if(d.auditState == 10){ }}
    <span>通过</span>
    {{#  } else if(d.auditState == 20){ }}
    <span>等待审核</span>
    {{#  } else if(d.auditState == 25){ }}
    <span>未通过</span>
    {{#  } else if(d.auditState == 30){ }}
    <span>通过</span>
    {{#  } }}
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>
<script>

    layui.config({
        version: '1572350921010' //为了更新 js 缓存，可忽略
    });

    layui.use([ 'layer', 'table', 'element', 'laydate','form'], function(){
        var layer = layui.layer //弹层
            ,table = layui.table //表格
            ,element = layui.element //元素操作
            ,form = layui.form
            ,laydate = layui.laydate; //表单

        //向世界问个好
        layer.msg('审核');


        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            var auditId = ''; //数组id
            if(layEvent === 'delete'){
                layer.confirm('确定删除选中行意见吗？', function(index){
                    //obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    auditId += data.auditId;
                    console.log('删除数据id：'+auditId);
                    layer.msg('删除成功', { icon: 1 });
                    //向服务端发送删除指令
                    $.ajax({
                        type: 'post',
                        url: '../../attachment/attachDelete', //数据接口
                        data: {
                            'auditId':auditId
                        },
                        dataType: 'json',
                        success: function (data) {
                            if(data.state > 0){
                                layer.msg('删除成功',{
                                    icon: 1,
                                    time: 1000,
                                    end: function () {
                                        table.reload('demo',{});
                                        //window.location.reload();
                                    }
                                });
                            }else{
                                layer.msg('删除失败',{
                                    icon: 1,
                                    time: 1000,
                                    end: function () {
                                        table.reload('demo',{});
                                        //window.location.reload();
                                    }
                                });
                            }

                        }
                    });
                });
            }
        });

    });

    //起始赋值事件
    function begins() {
        var form = layui.form
            ,$ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            ,table = layui.table;//表格
        //var demoListView = $('#demoList');
        var attachId = $("#attachId").val();
        //var fileHtml = "";
        console.log("================审核意见的附件表id"+attachId);
        var url = "../../attachment/selectByAttachId";

        table.render({
            elem: '#demo'
            //,height: 570
            ,even: true //隔行背景
            ,url: url //数据接口
            ,title: '用户表'
            ,page: true //开启分页
            ,toolbar: 'true' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,where:{
                auditAttachId:attachId
            }
            ,cols: [[ //表头
                {field: 'auditId', title: 'ID', width:60, sort: true, fixed: 'left',hide:true}
                ,{field: 'auditOpinion', title: '审核意见'}
                ,{field: 'creatTime', title: '审核时间', width:120, sort: true}
                ,{field: 'creater', title: '审核人', width:120}
                ,{field: 'auditState', title: '审核状态', width: 100, templet: '#tempLetState'}
            ]]
        });
    }

</script>
</body>
</html>